package nccloud.pubimpl.pu.bp;

import java.util.List;

import nc.bs.dao.BaseDAO;
import nc.impl.pubapp.pattern.data.vo.VOQuery;
import nc.jdbc.framework.processor.ColumnListProcessor;
import nc.pub.kk.cons.BilltypeCons;
import nc.pub.kk.cons.DefFieldCons;
import nc.vo.pu.m21.entity.OrderItemVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.pubapp.AppContext;
import nc.vo.pubapp.pattern.pub.SqlBuilder;

public class DetailsBp {
	
	private BaseDAO dao;

	public BaseDAO getDao() {
		if(this.dao == null) this.dao = new BaseDAO();
		return dao;
	}

	public OrderItemVO[] exec_queryByHpks(String[] pks) throws BusinessException {
		
		UFDateTime currTime = AppContext.getInstance().getServerTime();
		String currDate = currTime.toStdString().substring(0, 10);
		String currMonth = currDate.substring(0, 7);
		
		SqlBuilder sqlB = new SqlBuilder();
		sqlB.append("select b.pk_order_b from po_order_b b left join po_order h on h.pk_order=b.pk_order\r\n");
		sqlB.append("where h.dr=0 and b.dr=0 and h.forderstatus in (3,5)\r\n" + "and h.vtrantypecode not in ('");
		sqlB.append(BilltypeCons.POORDER_GDZC + "', '" + BilltypeCons.POORDER_PMD + "')\r\n");
		sqlB.append("and SUBSTRING(b.dplanarrvdate, 1, 7) <= '" + currMonth + "'\r\n");
		sqlB.append("and isnull(b.naccumarrvnum, 0) = 0\r\n");
		sqlB.append("and h.pk_order", pks);
		
		List<String> list = (List<String>) getDao().executeQuery(sqlB.toString(), new ColumnListProcessor());
		
		if(list != null && list.size() > 0) {
			String[] bids = new String[list.size()];list.toArray(bids);
			OrderItemVO[] vos = new VOQuery<OrderItemVO>(OrderItemVO.class).query(bids);
			return vos;
		}
		
		return null;
	}
}
